#include "qaddruntimedatadialog.h"
#include "ui_qaddruntimedatadialog.h"

#include "../../lib/corelib/qnamevalidator.h"

QAddRuntimeDataDialog::QAddRuntimeDataDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::QAddRuntimeDataDialog),
    m_nameEdit(new QNameEdit(this))
{
    ui->setupUi(this);
    ui->horizontalLayout->addWidget(m_nameEdit,1);
}

QAddRuntimeDataDialog::~QAddRuntimeDataDialog()
{
    delete ui;
}

void QAddRuntimeDataDialog::setNameList(const QStringList names)
{
    m_nameEdit->setIntermediateList(names);
}

void QAddRuntimeDataDialog::setCategoryList(const QStringList categorys)
{
    ui->category_list->addItems(categorys);
}

void QAddRuntimeDataDialog::on_pushButton_2_clicked()
{
    m_name=m_nameEdit->value();
    if(m_name=="")
    {
        return;
    }
    m_category=ui->category_list->currentText();
    close();
}

void QAddRuntimeDataDialog::on_pushButton_clicked()
{
    close();
}

QString QAddRuntimeDataDialog::getName()
{
    return m_name;
}

QString QAddRuntimeDataDialog::getCategory()
{
    return m_category;
}

void QAddRuntimeDataDialog::setCurrentCateGory(const QString category)
{
    int index=ui->category_list->findText(category);
    if(index==-1)
    {
        ui->category_list->lineEdit()->setText("Default");
    }
    else
    {
        ui->category_list->setCurrentIndex(index);
    }
}
